package xrc.controller;

import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xrc.service.TestService;
import xrc.service.impl.UserServiceImpl;


import java.sql.*;
import java.text.ParseException;
import java.util.List;

@RestController
public class UserController {

    @Autowired
    private UserServiceImpl userServiceImpl;

    //用户注册功能
    @PostMapping("/register")
    public List<Object> register(@RequestBody JSONObject user) throws SQLException, ClassNotFoundException {
        return userServiceImpl.register(user);
    }

    //用户登录功能
    @PostMapping("/login")
    public List<Object> login(@RequestBody JSONObject user){
        //System.out.println(user);
        return userServiceImpl.login(user);
    }

    @PostMapping("/modify")
    public List<Object> modify(@RequestBody JSONObject user){
        return userServiceImpl.modify(user);
    }

    //未完成
    @PostMapping("/get_waitforvote_list")
    public List<Object> getWaitForVoteList(@RequestBody JSONObject user) throws Exception {
        return userServiceImpl.getWaitForVoteList(user);
    }

    //投票发起者发布事项
    @PostMapping("/publish")
    public List<Object> publish(@RequestBody JSONObject event) throws Exception {
        return userServiceImpl.publish(event);
    }

    @PostMapping("/get_publishedvote_list")
    public List<Object> getPublishedVoteList(@RequestBody JSONObject user) throws SQLException, ParseException, ClassNotFoundException {
        return userServiceImpl.getPublishedVoteList(user);
    }

    @PostMapping("/preVote")
    public List<Object> preVote(@RequestBody JSONObject user) throws Exception {
        return userServiceImpl.preVote(user);
    }

    @PostMapping("/verify")
    public List<Object> verify(@RequestBody JSONObject user) throws Exception {
        return userServiceImpl.verify(user);
    }

    @PostMapping("/alluser")
    public List<Object> allUser(@RequestBody JSONObject user) throws SQLException, ClassNotFoundException {
        return userServiceImpl.allUser(user);
    }

    @PostMapping("/vote")
    public List<Object> vote(@RequestBody JSONObject user) throws Exception {
        return userServiceImpl.vote(user);
    }

    @PostMapping("/preCount")
    public List<Object> preCount(@RequestBody JSONObject user) throws Exception {
        return userServiceImpl.preCount(user);
    }

    @PostMapping("/getSum")
    public List<Object> getSum(@RequestBody JSONObject user) throws Exception {
        return userServiceImpl.getSum(user);
    }

    @GetMapping("/hello")
    public String hello(){
        return userServiceImpl.hello();
    }

    @PostMapping("/addY")
    public List<Object> addY(@RequestBody JSONObject user) throws Exception {
        return userServiceImpl.addY(user);
    }

    @PostMapping("/addE")
    public List<Object> addE(@RequestBody JSONObject user) throws Exception {
        return userServiceImpl.addE(user);
    }

}
